#include "SharedPtrTests.h"
#include "../TestFramework/TestSharedPtr.h"

namespace
{
    struct Test
    {
        Test()
            : First(5)
        {
        }

        int First;
    };

    TEST_CASE(TestEmptySharedPtr)
    {
        TestFramework::TestSharedPtr<Test> ptr;
        CHECK(!ptr.Get());
    }

    TEST_CASE(TestSharedPtrCreation)
    {
        TestFramework::TestSharedPtr<Test> ptr(new Test());
        CHECK(ptr.Get());
    }

    TEST_CASE(TestSharedPtrCopying1)
    {
        TestFramework::TestSharedPtr<Test> ptr1(new Test());
        TestFramework::TestSharedPtr<Test> ptr2(ptr1);
        CHECK(ptr1.Get() && ptr2.Get());
    }

    TEST_CASE(TestSharedPtrCopying2)
    {
        TestFramework::TestSharedPtr<Test> ptr1(new Test());
        TestFramework::TestSharedPtr<Test> ptr2 = ptr1;
        CHECK(ptr1.Get() && ptr2.Get());
    }

    TEST_CASE(TestSharedPtrAccessing)
    {
        TestFramework::TestSharedPtr<Test> ptr(new Test());
        CHECK(ptr.Get()->First == 5 && ptr->First == 5 && (*ptr).First == 5);
    }

    START_TEST_SUITE(SharedPtrTest, "SharedPtr test")
    {
        REGISTER_TEST(TestEmptySharedPtr);
        REGISTER_TEST(TestSharedPtrCreation);
        REGISTER_TEST(TestSharedPtrCopying1);
        REGISTER_TEST(TestSharedPtrCopying2);
        REGISTER_TEST(TestSharedPtrAccessing);
    }
    FINISH_TEST_SUITE
}

namespace Tests
{
    TestFramework::UnitTestPtr CreateSharedPtrTester()
    {
        CREATE_SUITE(SharedPtrTest)
    }
}
